package com.aiton.bamin.bamindaijiadrier.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;

import com.aiton.bamin.bamindaijiadrier.R;

import java.util.List;


/**
 * 常用联系人GridView的适配器
 */
public class MyPhoneAdapter extends BaseAdapter {


    private List<String> mPhoneList;
    private LayoutInflater inflater;

    class ViewHolder {
        Button button_contacts;
    }

    public MyPhoneAdapter(Context context, List<String> mPhoneList) {
        this.mPhoneList = mPhoneList;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mPhoneList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            View inflate = inflater.inflate(R.layout.contacts_item, null);
            holder.button_contacts = (Button) inflate.findViewById(R.id.button_contacts);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }


        final String phone = mPhoneList.get(position);
        if (mPhoneList.size() > 0) {
            holder.button_contacts.setText(phone);
        }
        return convertView;
    }
}